<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0"><meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />   
        <title>Welcome to Design Zone......</title>
        <link rel="stylesheet" type="text/css" href="../../scripts/ext/resources/css/ext-all.css" />
        <link rel="stylesheet" type="text/css" href="../../styles/dzbase.css" />
        <script type="text/javascript" src="../../scripts/ext/adapter/ext-base.js">
        </script>
        <script type="text/javascript" src="../../scripts/ext/ext-all.js">
        </script>
        <script type="text/javascript" src="../../scripts/i18nMessage.js">
        </script>
        <script type="text/javascript" src="../../scripts/utils.js">
        </script>
        <script type="text/javascript">
        	var quMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.quotation');
            var message = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=message');

            var calculator1 = function(){
                var value = Ext.getCmp('rmbUs').getValue();
                if(!value) return;
                Ext.getCmp('usRmb').setValue(1/value);
                Ext.getCmp('usRmb').focus();
                Ext.getCmp('usRmb').blur();
            }

            var calculator2 = function(){
            	var value = Ext.getCmp('rmbEu').getValue();
                if(!value) return;
                Ext.getCmp('euRmb').setValue(1/value);
                Ext.getCmp('euRmb').focus();
                Ext.getCmp('euRmb').blur();
            }

            var calculator3 = function(){
            	var value = Ext.getCmp('usEu').getValue();
                if(!value) return;
                Ext.getCmp('euUs').setValue(1/value);
                Ext.getCmp('euUs').focus();
                Ext.getCmp('euUs').blur();
            }
			
            Ext.onReady(function(){
                Ext.QuickTips.init();
                Ext.form.Field.prototype.msgTarget = 'side';
								
                var idValue = getPrarmeterValue(window.location, 'id');
                var startPage = getPrarmeterValue(window.location, 'startPage');
                var exchangeRateForm = new Ext.FormPanel({
                    labelAlign: 'left',
                    labelWidth: 120, 
                    url: '../../servlet/QuExchangeRateServlet?action=1',
                    frame: true,
                    reader: new Ext.data.XmlReader({
                        record: 'item'
                    }, [{
                        name: 'id',
                        mapping: 'id'
                    }, {
                        name: 'date',
                        mapping: 'date'
                    }, {
                        name: 'rmbUs',
                        mapping: 'rmbUs'
                    }, {
                        name: 'usRmb',
                        mapping: 'usRmb'
                    }, {
                        name: 'rmbEu',
                        mapping: 'rmbEu'
                    }, {
                        name: 'euRmb',
                        mapping: 'euRmb'
                    }, {
                        name: 'usEu',
                        mapping: 'usEu'
                    }, {
                        name: 'euUs',
                        mapping: 'euUs'
                    }]),
                    title: quMessage.get('ui.quotation.editexchangerate'),
                    bodyStyle: 'padding:5px 5px 5px 5px',
                    
                    items: [{
                        id: 'id',
                        name: 'id',
                        xtype: 'hidden'
                    },{
                        name: 'date',
                        fieldLabel: message.get('message.edit.date') + '(d/m/Y)',
                        xtype: 'datefield',
                        allowBlank: false,
                        blankText: message.get('message.edit.noblank')
                    },{
						xtype: 'fieldset',
						collapsible: true,
						title: '&nbsp;',
						autoHeight: true,
						items: [{
                            layout: 'column',
                            items: [{
                                columnWidth: .33,
                                layout: 'form',
                                items: [{
									id: 'rmbUs',
                                    name: 'rmbUs',
                                    fieldLabel: 'RMB<img src="../../images/icons/money_yen.png"/>&nbsp;/&nbsp;US<img src="../../images/icons/money_dollar.png"/>',
                                    xtype: 'numberfield',
                                    decimalPrecision: 4,
                                    anchor: '86%',
									width: '90%',
                                    allowBlank: false,
                                    blankText: message.get('message.edit.noblank'),
                                    maxLength: 64
                                },{
									id: 'usRmb',
                                    name: 'usRmb',
                                    fieldLabel: 'US<img src="../../images/icons/money_dollar.png"/>&nbsp;/&nbsp;RMB<img src="../../images/icons/money_yen.png"/>&nbsp;&nbsp;<img src="../../images/icons/calculator.png" onclick="calculator1()"/>',
                                    xtype: 'numberfield',
                                    decimalPrecision: 4,
                                    anchor: '86%',
									width: '90%',
                                    allowBlank: false,
                                    blankText: message.get('message.edit.noblank'),
                                    maxLength: 64
                                }]
							
							},{
                                columnWidth: .33,
                                layout: 'form',
                                items: [{
									id: 'rmbEu',
                                    name: 'rmbEu',
                                    fieldLabel: 'RMB<img src="../../images/icons/money_yen.png"/>&nbsp;/&nbsp;EU<img src="../../images/icons/money_euro.png"/>',
                                    xtype: 'numberfield',
                                    decimalPrecision: 4,
                                    anchor: '86%',
									width: '90%',
                                    allowBlank: false,
                                    blankText: message.get('message.edit.noblank'),
                                    maxLength: 64
                                },{
									id: 'euRmb',
                                    name: 'euRmb',
                                    fieldLabel: 'EU<img src="../../images/icons/money_euro.png"/>&nbsp;/&nbsp;RMB<img src="../../images/icons/money_yen.png"/>&nbsp;&nbsp;<img src="../../images/icons/calculator.png" onclick="calculator2()"/>',
                                    xtype: 'numberfield',
                                    decimalPrecision: 4,
                                    anchor: '86%',
									width: '90%',
                                    allowBlank: false,
                                    blankText: message.get('message.edit.noblank'),
                                    maxLength: 64
                                }]
							
							},{
                                columnWidth: .33,
                                layout: 'form',
                                items: [{
									id: 'usEu',
                                    name: 'usEu',
                                    fieldLabel: 'US<img src="../../images/icons/money_dollar.png"/>&nbsp;/&nbsp;EU<img src="../../images/icons/money_euro.png"/>',
                                    xtype: 'numberfield',
                                    decimalPrecision: 4,
                                    anchor: '86%',
									width: '90%',
                                    allowBlank: false,
                                    blankText: message.get('message.edit.noblank'),
                                    maxLength: 64
                                },{
									id: 'euUs',
                                    name: 'euUs',
                                    fieldLabel: 'EU<img src="../../images/icons/money_euro.png"/>&nbsp;/&nbsp;US<img src="../../images/icons/money_dollar.png"/>&nbsp;&nbsp;<img src="../../images/icons/calculator.png" onclick="calculator3()"/>',
                                    xtype: 'numberfield',
                                    decimalPrecision: 4,
                                    anchor: '86%',
									width: '90%',
                                    allowBlank: false,
                                    blankText: message.get('message.edit.noblank'),
                                    maxLength: 64
                                }]
							
							}]
						}]
					}],
                    
                    buttons: [{
                        text: message.get('message.edit.save'),
                        handler: function(){
                            if (exchangeRateForm.getForm().isValid()) {
                                //messageForm.hide();
                                exchangeRateForm.getForm().submit({
                                    method: 'post',
                                    success: function(form, action){
                                        //alert(form);
										
                                        messageTip.msg(message.get('message.tip'), message.get('message.edit.successful'));
                                        exchangeRateForm.getForm().reset();
                                        //messageForm.show();
                                    },
                                    failure: function(form, action){
                                        //alert(form);
                                        messageTip.msg(message.get('message.tip'), message.get('message.edit.unsuccessful'));
                                        //messageForm.show();
                                    }
                                });
                            }
                        }
                    },{
						text: message.get('message.edit.reset'),
						handler: function(){
							messageForm.getForm().reset();
						}
					}, {
                        text: message.get('message.edit.cancel'),
                        handler: function(){
                            if (startPage != null) {
                                window.location = 'exchange_rate_list.html?startPage=' + startPage;
                            }
                            else {
                                window.location = 'exchange_rate_list.html';
                            }
                        }
                    }]
                });
				
                exchangeRateForm.render('exchangeRate');
	
		
				if(idValue != null){
					document.getElementById('id').value = idValue;
					exchangeRateForm.getForm().load({url:'../../servlet/QuExchangeRateServlet?action=3&id=' + idValue, waitMsg:Ext.LoadMask.prototype.msg});
				}
            });
			
			
        </script>
    </head>
    <body>
        <div id="exchangeRate"></div>
    </body>
</html>
